<template>
  <div class="wrap">
    <div class="deleStatus" @click="show = true">
      消息
      <img src="@/assets/deleMsg.png" alt="" class="deleImg" />
    </div>
    <div class="main">
      <div class="titleWrap">
        <div
          class="titleItem"
          :class="{'titleItemActive': whichTitle == 0}"
          @click="changeTitleOptions(0)"
        >
          点赞我的
        </div>
        <div
          class="titleItem"
          :class="{'titleItemActive': whichTitle == 1}"
          @click="changeTitleOptions(1)"
        >
          我点赞的
        </div>
      </div>
      <!-- 点赞我的： -->
      <div class="forumList" v-if="whichTitle==0">
        <div v-for="(item, index) in resFromLikeList" :key="index">
          <div class="forumItem" v-if="item.msgType == 1" @click="jumpForumInfo(item.articleId)">
            <div class="itemTop">
              <img
                :src="$imgUrl + item.fromHeadImage"
                alt=""
                class="headPhoto"
                @click="jumpUserInfo"
              />
              <div class="leftWhopraise">
                <div class="name">
                  {{ item.fromNickName }} <em class="geryPraise">{{ item.content }}</em>
                </div>
                <div class="time">{{ item.createTime }}</div>
              </div>
            </div>
            <div class="itemBottom itemBottom2">
              <div class="whichForum">
                <img v-if="item.articleImageUrl" :src="$imgUrl+item.articleImageUrl[0]" alt="" class="forumImg" />
                <div class="rightIntro">
                  <div class="whoAt">{{ item.articleNickName }}的帖子</div>
                  <div class="forumTextInfor">
                    <!-- <em class="fontWeight">#故乡的云# </em> -->
                    {{ item.articleContent }}
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
        <div v-for="(item, index) in resFromLikeList" :key="index+'a'">
          <div class="forumItem" v-if="item.msgType == 2" @click="jumpForumInfo(item.articleId)">
            <div class="itemTop">
              <img
                :src="$imgUrl+item.fromHeadImage"
                alt=""
                class="headPhoto"
                @click="jumpUserInfo"
              />
              <div class="leftWhopraise">
                <div class="name">{{ item.fromNickName }} <em class="geryPraise">{{ item.content }}</em></div>
                <div class="time">{{ item.createTime }}</div>
              </div>
            </div>
            <div class="itemBottom">
              <div class="whichComment">
                {{item.toNickName}}：{{item.commentContent}}
              </div>
              <div class="whichForum">
                <img v-if="item.articleImageUrl" :src="$imgUrl+item.articleImageUrl[0]" class="forumImg" />
                <div class="rightIntro">
                  <div class="whoAt">{{ item.articleNickName }}的帖子</div>
                  <div class="forumTextInfor">
                    <!-- <em class="fontWeight">#故乡的云# </em> -->
                   {{ item.articleContent }}
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>

      <!-- 我点赞的： -->
      <div class="forumList" v-else>
        <div v-for="(item, index) in  resToLikeList" :key="index">
          <div class="forumItem" v-if="item.msgType == 1" @click="jumpForumInfo(item.articleId)">
            <div class="itemTop">
              <img
                :src="$imgUrl + item.headImage"
                alt=""
                class="headPhoto"
                @click="jumpUserInfo"
              />
              <div class="leftWhopraise">
                <div class="name">
                  {{ item.fromNickName }} <em class="geryPraise">我{{ item.content }}</em>
                </div>
                <div class="time">{{ item.createTime }}</div>
              </div>
            </div>
            <div class="itemBottom itemBottom2">
              <div class="whichForum">
                <img v-if="item.articleImageUrl" :src="$imgUrl+item.articleImageUrl[0]" alt="" class="forumImg" />
                <div class="rightIntro">
                  <div class="whoAt">{{ item.articleNickName }}的帖子</div>
                  <div class="forumTextInfor">
                    <!-- <em class="fontWeight">#故乡的云# </em> -->
                    {{ item.articleContent }}
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
        <div v-for="(item, index) in resToLikeList" :key="index+'a'">
          <div class="forumItem" v-if="item.msgType == 2" @click="jumpForumInfo(item.articleId)">
            <div class="itemTop">
              <img
                :src="$imgUrl + item.headImage"
                alt=""
                class="headPhoto"
                @click="jumpUserInfo"
              />
              <div class="leftWhopraise">
                <div class="name"><em class="geryPraise">我{{ item.content }}</em></div>
                <div class="time">{{ item.createTime }}</div>
              </div>
            </div>
            <div class="itemBottom">
              <div class="whichComment">
                {{item.articleNickName}}：{{item.commentContent}}
              </div>
              <div class="whichForum">
                <img v-if="item.articleImageUrl" :src="$imgUrl+item.articleImageUrl[0]" class="forumImg" />
                <div class="rightIntro">
                  <div class="whoAt">{{ item.articleNickName }}的帖子</div>
                  <div class="forumTextInfor">
                    <!-- <em class="fontWeight">#故乡的云# </em> -->
                   {{ item.articleContent }}
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
        <!-- <div class="forumItem">
          <div class="itemBottom">
            <div class="whichComment">该帖子已被删除</div>
            <div class="whichForum whichForum1">
              <div class="whoAt">
                <em class="name">@王二小</em>
                <em class="time">10-05 12:00</em>
                <em class="attention attention2">取消关注</em>
              </div>
            </div>
          </div>
        </div> -->
      </div>
    </div>

    <!-- 遮罩层-清空消息： -->
    <div class="maskWrap" v-if="show">
      <div class="maskBg" @click="show = false"></div>
      <div class="chooseNumWrap">
        <div class="optionsItem" @click="getClearMessage(1)">清空点赞我的</div>
        <div class="optionsItem" @click="getClearMessage(4)">清空我点赞的</div>
        <div class="optionsItem" @click="getClearMessage(6)">清空全部消息</div>
        <div class="optionsItem dele" @click="show = false">取消</div>
      </div>
    </div>
  </div>
</template>

<script>
import { Switch } from "vant";
import { apiLikeMessageList, apiLikeRecordList,apiClearMessage } from "@/request/api"; // api接口

export default {
  name: "App",
  data() {
    return {
      show: false,
      resToLikeList: [], //我点赞的列表
      resFromLikeList: [], //点赞我的列表
      whichTitle:0, //0-点赞我的，1-我点赞的
    };
  },
  mounted() {
    document.querySelector("body").setAttribute("style", "background-color:#F2F4FA");
    this.getLikeRecordList();
    this.getLikeMessageList();
  },
  methods: {
    changeTitleOptions(num) {
      this.whichTitle = num;
    },
    //获取我点赞的消息列表
    getLikeRecordList() {
      apiLikeRecordList({}).then((res) => {
        console.log('res',res)
        var dataRes2 = res.data
        dataRes2.map(item=>{
          if(item.articleImageUrl){
            item.articleImageUrl = item.articleImageUrl.split(',')
          }
        })
        this.resToLikeList.push(...dataRes2)
        console.log("我点赞的resToLikeList", this.resToLikeList);
      });
    },
    //获取点赞我的消息列表
    getLikeMessageList() {
      apiLikeMessageList({}).then((res) => {
        var dataRes = res.data
        dataRes.map(item=>{
          if(item.articleImageUrl){
            item.articleImageUrl = item.articleImageUrl.split(',')
          }
        })
        this.resFromLikeList.push(...dataRes)
        console.log("点赞我的resFromLikeList", this.resFromLikeList);
      });
    },
    //清空消息的操作：
    getClearMessage(i) {
      apiClearMessage({
        msgType:i
      }).then((res) => {
        if(res.code==200){
          this.show = false
          this.$toast.success('已清空')
        }
      });
    },
    
    jumpUserInfo() {
      this.$router.push({
        path: "/pages/forumPersonalCenter",
        query: {
          //传递参数
        },
      });
    },
    jumpForumInfo(id) {
      this.$router.push({
        path: "/pages/forumInfo",
        query: {
          //传递参数
          forumId:id
        },
      });
    },
  },
  created() {},
  components: {
    [Switch.name]: Switch,
  },
};
</script>

<style scoped>
.deleStatus {
  font-size: 16px;
  font-weight: 500;
  color: #181818;
  text-align: center;
  height: 50px;
  line-height: 50px;
}
.deleImg {
  width: 13px;
  height: 13px;
}
.main {
  width: 95%;
  margin: 0 auto;
}
.titleWrap {
  width: 90%;
  margin: 0 auto;
  display: flex;
  justify-content: space-around;
}
.titleItem {
  width: 105px;
  height: 37px;
  line-height: 37px;
  text-align: center;
  border-radius: 19px;
  font-size: 14px;
  font-weight: 400;
  color: #666666;
}
.titleItemActive {
  background: #181818;
  color: #fff;
}
.forumList {
}
.forumItem {
}
.itemTop {
  overflow: hidden;
  margin-top: 25px;
}
.headPhoto {
  float: left;
  height: 40px;
  width: 40px;
  border-radius: 40px;
  float: left;
}
.leftWhopraise {
  float: left;
  margin-left: 10px;
}
.name {
  font-size: 14px;
  font-weight: 400;
  color: #181818;
}
.geryPraise {
  font-size: 14px;
  font-weight: 400;
  color: #666666;
}
.time {
  font-size: 11px;
  font-weight: 300;
  color: #999999;
  margin-top: 5px;
}
.itemBottom {
  background: #ffffff;
  border-radius: 20px;
}
.itemBottom2 {
  padding-top: 15px;
  margin-top: 15px;
}
.whichComment {
  font-size: 13px;
  font-weight: 400;
  color: #181818;
  margin: 14px 16px;
  padding-top: 14px;
  padding-bottom: 14px;
  border-bottom: 1px solid #e5e5e5;
}
.whichForum {
  overflow: hidden;
}
.whichForum1 {
  margin-left: 20px;
}
.attention2 {
  font-size: 10px;
  font-weight: 500;
  color: #ffffff !important;
  background-color: #b5b3b2 !important;
  float: right;
  margin-right: 20px;
}
.forumImg {
  float: left;
  width: 88px;
  height: 102px;
  margin-left: 14px;
  margin-bottom: 16px;
}
.rightIntro {
  width: calc(100% - 127px);
  float: left;
  margin-left: 15px;
  font-size: 11px;
  font-weight: 500;
  color: #181818;
}
.whoAt {
  font-size: 13px;
  font-weight: 400;
  margin: 15px 0px 13px 0px;
}
.name {
}
.time {
  padding-left: 5px;
}
.attention {
  display: inline-block;
  height: 23px;
  line-height: 23px;
  text-align: center;
  background: #181818;
  border-radius: 12px;
  color: #fff;
  font-size: 10px;
  padding: 0px 10px;
  margin-left: 30px;
}
.forumTextInfor {
}
.praiseOptions {
  overflow: hidden;
  margin-top: 15px;
  margin-bottom: 15px;
  width: 170px;
  float: right;
}
.praiseItem {
  float: left;
  margin: 0px 10px;
}
.optionsCount {
}
.optionsImg {
  width: 13px;
  height: 11px;
}
.optionsImg1 {
  width: 12px;
  height: 11px;
}
.optionsImg2 {
  width: 13px;
  height: 3px;
  padding-bottom: 3px;
}
.fontWeight {
  font-weight: 600;
}
.maskWrap {
}
.maskBg {
  width: 100%;
  min-height: 100vh;
  opacity: 0.35;
  background-color: #000;
  position: fixed;
  top: 0px;
}
.chooseNumWrap {
  width: 100%;
  background-color: #fff;
  position: fixed;
  bottom: 0px;
  border-radius: 20px 20px 0px 0px;
}
.optionsItem {
  height: 50px;
  line-height: 50px;
  border-bottom: 1px solid #eee;
  color: #000;
  font-size: 14px;
  text-align: center;
}
.dele {
  background-color: #eee;
  border-radius: 20px;
  width: 90%;
  margin: 5px auto;
  height: 40px;
  line-height: 40px;
}
</style>
